<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
      // Load the Visualization API and the bar chart package.
      google.load("visualization", "1", {packages:['table']});
      
      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(initializeData);

      // Once visualization API is loaded, retrieve data and set callbacks to run once retrieved.
      function initializeData() {
        // Get all of the dorm data from the spreadsheet.
        var dormDataURL = 'http://spreadsheets.google.com/tq?key=0Av0U6TKHfzXYdG1vUnduR0RVTktyR1ZtNjAtSE9Qbmc&range=A3:F21&gid=0';
        var dormDataQuery = new google.visualization.Query(dormDataURL);
        dormDataQuery.setRefreshInterval(5);
 
        // Set a callback to run when the dorm data has been retrieved.
        dormDataQuery.send(displayDormData);
      }

      
      // Callback that gets the dorm data and creates DataViews to display each table individually.
      function displayDormData(response) {
        // Process errors, if any.
        if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }
        
        // Get the dorm data table.
        var data = response.getDataTable();
        
        // Create the Ilima power data view.
        var ilimaView = new google.visualization.DataView(data);
        ilimaView.setColumns([1, 2, 3]);
        ilimaView.setRows(0, 5);
        var ilimaViewTable = new google.visualization.Table(document.getElementById('ilima_chart_div'));
        ilimaViewTable.draw(ilimaView, {width: '300'});
        
        // Create the Mokihana power data view.
        var mokihanaView = new google.visualization.DataView(data);
        mokihanaView.setColumns([1, 2, 3]);
        mokihanaView.setRows(6, 11);
        var mokihanaViewTable = new google.visualization.Table(document.getElementById('mokihana_chart_div'));
        mokihanaViewTable.draw(mokihanaView, {width: '300'});

        // Create the Lehua power data view.
        var lehuaView = new google.visualization.DataView(data);
        lehuaView.setColumns([1, 2, 3]);
        lehuaView.setRows(12, 17);
        var lehuaViewTable = new google.visualization.Table(document.getElementById('lehua_chart_div'));
        lehuaViewTable.draw(lehuaView, {width: '300'});
        
        // Create the Ilima energy view.
        var ilimaEnergyView = new google.visualization.DataView(data);
        ilimaEnergyView.setColumns([1, 4, 5]);
        ilimaEnergyView.setRows(0, 5);
        var ilimaEnergyViewTable = new google.visualization.Table(document.getElementById('ilima_energy_chart_div'));
        ilimaEnergyViewTable.draw(ilimaEnergyView, {width: '300'});
        
        // Create the Mokihana energy view.
        var mokihanaEnergyView = new google.visualization.DataView(data);
        mokihanaEnergyView.setColumns([1, 4, 5]);
        mokihanaEnergyView.setRows(6, 11);
        var mokihanaEnergyViewTable = new google.visualization.Table(document.getElementById('mokihana_energy_chart_div'));
        mokihanaEnergyViewTable.draw(mokihanaEnergyView, {width: '300'});
        
        // Create the lehua energy view.
        var lehuaEnergyView = new google.visualization.DataView(data);
        lehuaEnergyView.setColumns([1, 4, 5]);
        lehuaEnergyView.setRows(12, 17);
        var lehuaEnergyViewTable = new google.visualization.Table(document.getElementById('lehua_energy_chart_div'));
        lehuaEnergyViewTable.draw(lehuaEnergyView, {width: '300'});
        
   }


    </script>
  </head>

  <body>
    <table border="1">
    <tr><td>
    <h3>Ilima Power Data</h3>
    <div id="ilima_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    <td>
    <h3>Mokihana Power Data</h3>
    <div id="mokihana_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    <td>
    <h3>Lehua Power Data</h3>
    <div id="lehua_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    </tr>
    </table>
    
    <table border="1">
    <tr><td>
    <h3>Ilima Energy Data</h3>
    <div id="ilima_energy_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    <td>
    <h3>Mokihana Energy Data</h3>
    <div id="mokihana_energy_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    <td>
    <h3>Lehua Energy Data</h3>
    <div id="lehua_energy_chart_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    </td>
    </tr>
    </table>
    
    
  </body>
</html>

